package com.zhanbo.zhanbowymusic.main.mine.like.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.mwx.baselib.base.BaseBindingAdapter;
import com.mwx.baselib.bean.SongBean;
import com.mwx.baselib.net.LikeMusic;
import com.mwx.baselib.utils.GlideUtils;
import com.zhanbo.zhanbowymusic.R;
import com.zhanbo.zhanbowymusic.databinding.ItemLikeBinding;

/**
 * 我喜欢的音乐列表
 */
public class LikeMusicListAdapter extends BaseBindingAdapter<SongBean, ItemLikeBinding> {
    public LikeMusicListAdapter(Context context) {
        super(context);
    }

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_like;
    }

    @Override
    protected void onBindItem(ItemLikeBinding binding, SongBean item) {
        binding.likeListItemNum.setText("0"+(getPosition()+1));
        if (item.getIsLike()==1){
            binding.ivLike.setImageResource(R.mipmap.like);

        }else {
            binding.ivLike.setImageResource(R.mipmap.like_no);
        }
        binding.ivLike.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.setIsLike(item.getIsLike()==1?0:1);
                LikeMusic.like(context,item.getId()+"");
                getItems().remove(item);
                notifyDataSetChanged();
            }
        });
        GlideUtils.loadImageRounded10(context,item.getCoverImg(),binding.likeListItemIcon);
        binding.likeListItemSong.setText(TextUtils.isEmpty(item.getName())?"":item.getName());
        binding.tvListSingle.setText(TextUtils.isEmpty(item.getArtistName())?"":item.getArtistName());
        binding.tvAlbumName.setText(TextUtils.isEmpty(item.getAlbumName())?"":item.getAlbumName());
    }
}
